package com.zkjl.protect_business.utils;

import com.zkjl.protect_business.entity.Notice;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.util.Map;

public class BeanUtil extends cn.hutool.core.bean.BeanUtil {


    public static <T> T getToCamelCase(T bean, Object object) {

        Map<String, Object> map = beanToMap(object);

        return (T) fillBeanWithMap(map, bean, true, false);

    }


    /**
     * 指定值是否是String类型
     * @param obj
     * @param key
     * @return 返回指定字段实际的索引字段
     */
    public static <T> String isString(Class<T> obj, String key) {

        Field[] fields1 = obj.getDeclaredFields();
        for (Field field1 : fields1) {

            String name = field1.getName();
            if (name.equals(key)) {
                if (field1.getGenericType().toString().equals("class java.lang.String")) {

                    org.springframework.data.elasticsearch.annotations.Field annotation = field1.getAnnotation(org.springframework.data.elasticsearch.annotations.Field.class);
                    if (annotation != null) {
                        String name1 = annotation.name();
                        if (StringUtils.isNotBlank(name1)) {
                            return name1;
                        }

                    }

                    return key;
                }
            }

        }
        return key;
    }


}
